Skip to content

ci: cancel superseded PR runs - #852

Open
niteshb3495 wants to merge 2 commits into
rs:masterfrom
niteshb3495:ci/cancel-superseded-runs-and-test-timeout
Open

niteshb3495 wants to merge 2 commits into
rs:masterfrom
niteshb3495:ci/cancel-superseded-runs-and-test-timeout

Conversation

@niteshb3495

@niteshb3495 niteshb3495 commented Dec 4, 2026 •

Copy link
Copy Markdown

A small change to .github/workflows/test.yml:

Cancel superseded PR runs. Adds a concurrency group keyed on the PR number, so pushing a new commit to a pull request cancels that PR's older in-progress Test run. cancel-in-progress is only true for pull_request events. Non-PR events get a unique concurrency group keyed by github.run_id, so pushes never replace pending pushes, and push, tag, schedule and manual runs are never cancelled (this includes pushes to master).

Why: from the public Actions data for the 100 most recent runs (8 Sep - 3 Dec 2026), 5 of 12 consecutive same-branch pairs of Test runs overlapped, i.e. the newer run started before the older one had finished. One commit also ran Test for both push and pull_request. I'm not quoting a time saving: many of those runs waited for approval, so their wall times aren't reliable. The runners are free on a public repo, so the gain is mostly faster feedback and less queueing.

One small extra on the test job (the coverage job is untouched, since the coverage action may need to write):

  • permissions: contents: read, since the job only checks out and runs go test.

Checked: actionlint reports nothing on the file. The change merges cleanly with #793 and #775, which touch different lines of the same file.

Add a concurrency group that cancels an older in-progress run for the same PR (master pushes are not cancelled), set contents: read on the test job, and add a 15 minute timeout to it.

rs commented Dec 4, 2026

Copy link
Copy Markdown
Owner

Could you give non-PR events a unique concurrency group (for example one keyed by github.run_id)? With the current github.ref fallback, pushes on the same ref can still replace an earlier pending push even though they won't cancel a running one. That is different from the PR-only behavior described here. Could you also base the 15-minute timeout on the slowest Ubuntu/macOS matrix legs, or leave the timeout to a separate change?

Key the concurrency group by github.run_id for non-pull_request events so
pushes never replace a pending push on the same ref. Only pull_request
runs cancel in progress. Drop the 15-minute test job timeout, per review.
@niteshb3495

Copy link
Copy Markdown
Author

Thanks for the review, @rs! Good catch on the pending-push case. I've updated the PR: non-PR events now get a unique concurrency group keyed by github.run_id, so only superseded PR runs are ever cancelled, and I've dropped the timeout to keep this change focused. The description is updated to match. Ready for another look whenever you have time.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants